Socket
Socket
Sign inDemoInstall

print-code

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

print-code

Print visualized slice of code from its content, line and column for CLI


Version published
Weekly downloads
11
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

print-code

Print visualized slice of code from its content, line and column for CLI.

Install

$ npm install print-code --save

Usage

var code = require('print-code');
code(content)
  .highlight(4)
  .slice(1, 6)
  .max_columns(68)
  .arrow_mark(4, 10)
  .print()

And then the output might be (Line No 4 is red):

    1| 'use strict';
    2|
    3| module.exports = code
    4| code.Code = Code
----------------^ column: 10
    5|
.slice([from] [, to])

Specify which lines should be printed.

  • from Number= The line number begins to be printed, and the value will be parseInt()ed. If not specified, it will print all lines. If
  • to Number= If not specified, it will only print the line of from
code(content).slice().print();       // print all code
code(content).slice(10).print();     // print line 10
code(content).slice(10, 20).print(); // print lines from [10, 20)

Special cases:

code(content).slice(-1, 10).print(); // will print lines from [0, 10)
code(content).slice(0, -1).print();  // will print lines except for the last line.
code(content).slice(10, 9);          // will only print line 10
code(content).slice(10, 11);         // will print line 10
.highlight(line [, ...])

Specify which line number(s) should be highlighted.

  • line Number The number of code line, starts from 1
.max_columns(max)

Limit the max columns to be printed.

  • max Number= default to the max columns of the current terminal.
.arrow_mark(line, column)

Set a mark, and draw an arrow mark to the target coordinate (line, column).

.get()

Get the formated result content.

.print()

console.log the formated result content.

License

MIT

Keywords

FAQs

Package last updated on 20 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc